// pages/doctor/doctor.js
const { $Message } = require('../../iview/base/index');
const urlApi = require('../../utils/server.api.js')
const util = require('../../utils/util.js')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    totalObj: [],
    title: "挂号记录",
    totalPrice: 0,
    notPayData: [],
    sickName: "",
    sickCard: "",
    patientId: "",
    show: "hidden",
    type: ""
  },

  //获取待付款列表
  getRegisterLog:function(type){
    const that = this;
    this.setData({
      type:type
    })
    console.log("类类型类型类型型",type)
    var url = type == 0 ? urlApi.getRegisterLogUrl():
              type == 1 ? urlApi.getMZPayLogUrl():
              type == 2 ? urlApi.getPayLogUrl():
              type == 3 ? urlApi.getinHPayLogUrl():
              type == 4 ? urlApi.getDepositLogUrl() : urlApi.getPayLogUrl();              
    var title = type == 0?"挂号记录":
                type == 1?"缴费记录":
                type == 2?"门诊缴费记录":
                type == 3?"住院缴费记录":
                type == 4?"押金补交记录" : "缴费记录"
    wx.setNavigationBarTitle({
      title: title,
    })
    this.setData({
      title: title
    })
    wx.request({
      url: url,
      method: "get",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        patientName: app.globalData.userInfo.name,
        patientId: that.data.patientId
      },
      success: function (reponse) {
        console.log(reponse.data.data)
        var data = reponse.data.data;
        var arr = new Array();
        if (data != undefined && data.length > 0){
          for (var i of data) {
            if (that.data.type == 0 && i.regItemAmount != null){
              i.status = i.regStatus == 0 ? "挂号成功" : 
                         i.regStatus == 1 ? "待就诊" :
                         i.regStatus == 2 ? "就诊中" :
                         i.regStatus == 3 ? "就诊完成" :
                         i.regStatus == 4 ? "已退号" : "作废";
              i.name = app.globalData.userInfo.name;
              i.detail = "身份证：" + app.globalData.userInfo.idCard;
              i.price = i.regItemAmount;
              i.date = util.format(i.createTime);
              arr.push(i)
            } else if (that.data.type == 2) {
              i.status = i.orderStatus == 0 ? "未支付" : 
                         i.orderStatus == 1 ? "支付成功" :
                         i.orderStatus == 2 ? "支付超时" : "支付失败";
              i.name = app.globalData.userInfo.name;
              i.detail = "身份证：" + app.globalData.userInfo.idCard;
              i.price = i.orderAmount;
              i.date = util.format(i.createTime);
              arr.push(i)
            }
          }
          that.setData({
            notPayData: arr
          })
          console.log(that.data.notPayData)
        } else {
          that.setData({
            show: "show",
          })
        }
      }
    })
  },

  detailFun:function(){
    if(this.data.type == 0){
      wx.navigateTo({
        url: '/pages/GHDetail/GHDetail',
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var type = options.type;
    this.setData({
      sickName: app.globalData.userInfo.name,
      sickCard: app.globalData.userInfo.idCard,
      patientId: app.globalData.userInfo.patientId
    })
    this.getRegisterLog(Number(type));
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
})
